import { Vector3 } from '../core/math/Vector3'
/**
 * 粒子动画类
 */
export class Action {
    /**
     * 构造函数，传入时间数组与变化值数组
     */
    constructor(timeArray, valueArray) {
        this.times = timeArray || []
        this.values = valueArray || []
    }
    
    /**
     * 根据时间进行插值
     */
    lerp(t) {
        if(this.times.length == 0) return
        let i = 0, n = this.times.length
        while(i < n && t > this.times[i]) i++
        if(i == 0) return this.values[0]
        if(i == n) return this.values[n-1]
        const ratio = (t - this.times[i-1]) / (this.times[i] - this.times[i-1])
        if(this.values[0] instanceof Vector3) {
          return this.values[i-1].clone().lerp(this.values[i], ratio)
        } else {
          return this.values[i-1] + ratio * (this.values[i] - this.values[i-1])
        }
    }
}
